axios.defaults.baseURL = "http://api-breakingnews-web.itheima.net"

axios.interceptors.request.use(
  function (config) {
    if (config.url.indexOf('/my') !== -1) {
      config.headers.Authorization = localStorage.getItem('token')
    }

    return config

  },
  function (error) {
    return Promise.reject(error)
  }
)


axios.interceptors.response.use(function (response) {
  // 对响应数据做点什么
  if (response.data.status === 1 && response.data.message === "身份认证失败！") {
    location.href = '/login.html'
  }
  return response;
}, function (error) {
  // 对响应错误做点什么
  return Promise.reject(error);
});